<?php
namespace app\backstage\logic;
use think\Db;
class Vivo
{
    /*列表数据获取*/
    public function getList($params)
    {
        $field = '*';

        $params['channel_id'] = request()->_user->id;
        $params['status'] = 1;

        $condition[] = ['channel_id', 'in', 'not_empty', 'channel_id'];
        $condition[] = ['accountname', 'eq', 'require', 'accountname'];
        $condition[] = ['status', 'eq', 'require', 'status'];
        $condition[] = ['akey', 'eq', 'require', 'akey'];

        $where = buildQueryCondition($condition, $params);

        if (isset($params['field'])) {
            $orderBy = [$params['field'] => $params['order']];
        } else {
            $orderBy = ['id' => 'DESC'];
        }

        $Backhaul = \think\facade\App::model('Vivo');
        $list = $Backhaul->getList($where, $field, $params['page'], $params['limit'], $orderBy);

        $result['count'] = $Backhaul->getTotalNumber($where);
        $result['list'] = $list;
        return $result;
    }

    /*数据获取*/
    public function getInfo($where)
    {
        $field = '*';
        $Backhaul = \think\facade\App::model('Vivo');

        $info = $Backhaul->getOne($where,$field);

        return $info;
    }

    /*数据添加*/
    public function addInfo($data)
    {
        $Backhaul = \think\facade\App::model('Vivo');
        $res = $Backhaul->insertRecord($data);

        if($res){
            return ['code'=>100,'msg'=>'操作成功'];
        }

        return ['code'=>102,'msg'=>'操作失败'];
    }

    /*数据编辑*/
    public function editInfo($where,$data)
    {
        $Backhaul = \think\facade\App::model('Vivo');
        $res = $Backhaul->updateRecord($where,$data);

        if($res){
            return ['code'=>100,'msg'=>'操作成功'];
        }

        return ['code'=>102,'msg'=>'操作失败'];
    }

    /*数据删除*/
    public function delInfo($where)
    {
        $Backhaul = \think\facade\App::model('Vivo');
        $res = $Backhaul->deleteRecord($where);

        if($res){
            return ['code'=>100,'msg'=>'操作成功'];
        }

        return ['code'=>102,'msg'=>'操作失败'];
    }

    /*数据处理*/
    public function dataProcessing($params)
    {
        if (request()->_role->alias == 'channel') {
            $data['channel_id'] = request()->_user->id;
        }else{
            $data['channel_id']             = $params['channel_id'];
        }

        $data['link_id']                = $params['link_id'];
        $data['advert_media_id']        = $params['advert_media_id'];
        $data['report_ab']              = $params['report_ab'];
        //$data['report_jb']              = $params['report_jb'];
        //$data['report_rb']              = $params['report_rb'];
        $data['report_ao']              = $params['report_ao'];
        //$data['report_old_fans']        = $params['report_old_fans'];
        $data['report_caliber']         = $params['report_caliber'];
        $data['report_full']            = $params['report_full'];
        $data['report_order_bn']        = $params['report_order_bn'];
        $data['status']                 = $params['status'];

        if(isset($params['misreporting_loop_proportion']))
        {
            $data['misreporting_loop_proportion'] = $params['misreporting_loop_proportion'];
        }
        if(isset($params['misreporting_percentage']))
        {
            $data['misreporting_percentage'] = $params['misreporting_percentage'];
        }
        if(isset($params['misreporting_type']))
        {
            $data['misreporting_type'] = $params['misreporting_type'];
        }
        if(isset($params['order_amount_below']))
        {
            $data['order_amount_below'] = $params['order_amount_below'];
        }
        if(isset($params['order_amount_above']))
        {
            $data['order_amount_above'] = $params['order_amount_above'];
        }
        if(isset($params['hourValue']))
        {
            $data['hourValue'] = $params['hourValue'];
        }
        if(isset($params['vip_order_switch']))
        {
            $data['vip_order_switch'] = $params['vip_order_switch'];
        }

        return ['data'=>$data];
    }

}